<template>
  <!--收款确认-->
  <div>
    <div class="msg">
      <div class="weui-media-box weui-media-box_appmsg" v-for="item in orderDetailList">
        <div class="weui-media-box__hd">
          <img :src="item.coverImg | imgPathFilter" alt="" class="weui-media-box__thumb" width="100" height="82">
        </div>
        <div class="weui-media-box__bd">
          <input v-model="orderId" hidden="true">
          <h4 class="weui-media-box__title">{{item.goodsName}}</h4>
          <p class="weui-media-box__desc">{{item.unitPrice}}元</p>
        </div>
        <span class="num">×{{item.buyNum}}</span>
      </div>
    </div>

    <div class="divider"></div>
    <p class="total">总计 <span>{{order.totalPrice}}元</span></p>
    <div class="tip">
      <p>核对会员信息无误后，确认收款</p>
      <p>会员登录帐号：{{user.accountName}}</p>
    </div>
    <p class="choose">选择支付方式</p>
    <ul class="chooseway">
      <li v-for="(item,index) in radios" :key="item.index">
        <div class="radio-box">
          <label><img :src="item.paywayIcon | imgPathFilter" alt="" width="20">{{item.paywayName}}</label>
          <span class="radio" :class="{'on':item.isChecked}"></span>
          <input v-model="paywayId" :value="item.paywayId" class="input-radio" :checked='item.isChecked'
                 @click="check(index)" type="radio" :id="item.index">
        </div>
      </li>
    </ul>

    <wv-group title="备注" class="beizhus">
      <wv-textarea placeholder="请输入备注" :rows="6" show-counter max-length="500" v-model="remark"></wv-textarea>
    </wv-group>
    <p class="uploadtitle">上传支付凭证</p>
    <div class="upload" @click="showActionsheet()">
      <p>
        <img src="../../../assets/upload.png" alt="" width="36" v-if="filePath==''">
        <img :src="filePath | imgPathFilter" width="100%" height="100%" v-else>
      </p>
    </div>

    <p class="offer" @click="goCheck()">收款确认</p>

    <div class="model" v-show="isvisible">
      <div class="bg"></div>
      <div class="modelContent">
        <img src="../../../assets/close.png" alt="" width="15" @click="isvisible=false">
        确保会员已足额支付款项后，请勾选正确支付方式并收款确认
        <p class="btn">
          <button tag="button" @click="gatheringMoneySub()">确认已收款</button>
          <button @click="isvisible=false">取消</button>
        </p>
      </div>
    </div>
  </div>
</template>

<script type="text/ecmascript-6">
  import {getPayUnderInfo, uploadImg, getPayWayList, gatheringMoneySub} from '../../../../test/unit/http'
  import {wxApi} from '../../../../test/unit/flyme_weixin'
  import {Toast} from 'we-vue'

  export default {
    name: '',
    props: {},
    data() {
      return {
        src: require('../../../assets/guibin.png'),
        payType: 'POS刷卡',
        radios: [],
        isvisible: false,
        orderId: '',
        paywayId: '',
        filePath: '',
        remark: '',
        user: {},
        orderDetailList: [],
        order: {},
        show: false
      };
    },
    methods: {
      check(index) {
        // 先取消所有选中项
        this.radios.forEach((item) => {
          item.isChecked = false;
        });
        //再设置当前点击项选中
        this.payType = this.radios[index].value;
        // 设置值，以供传递
        this.radios[index].isChecked = true;
      },
      showActionsheet() {
        this.initChooseImageWxapi();
      },
      goUploadImg(params) {
        uploadImg(params).then(res => {
          if (res.code == 100) {
            this.filePath = res.object.filePath;
          } else {
            Toast.fail('上传失败');
          }
        })
      },
      initChooseImageWxapi() {
        let businessKey = this.$route.query.orderId;
        let that = this;
        wxApi.chooseImage({
          count: 1,
          callback: function (res, localIds) {
            let imgId = res.serverId;
            let params = {
              'pojoName': 'gatheringRecord',
              'businessKey': businessKey,
              'imgId': imgId
            };
            that.goUploadImg(params);
          }
        });
      },
      goCheck() {
        let result = this.$myUtils.isNull(this.filePath);
        if (result) {
          Toast.text('请上传收款凭证');
          return;
        }
        this.isvisible = true;
      },
      gatheringMoneySub() {
        this.show = true;
        let params = {
          orderId: this.order.orderId,
          paywayId: this.paywayId,
          filePath: this.filePath,
          remark: this.remark,
          isCheck: 2,
        };
        gatheringMoneySub(params).then(res => {
          if (res.code === 100) {
            this.$router.push({name: 'confirmend', query: {'gatheringRecordId': res.object.gatheringRecordId}});
          } else {
            Toast.fail(res.info);
          }
        })
      }
    },
    mounted() {
    },
    created() {
      wxApi.init();
      let orderId = this.$route.query.orderId;
      getPayUnderInfo({orderId: orderId}).then(res => {
        console.log(res);
        if (res.code == 100) {
          this.user = res.object.user;
          this.order = res.object.order;
          this.orderDetailList = res.object.orderDetailList;
        } else {
          Toast.fail(res.info);
        }
      });
      getPayWayList({}).then(res => {
        let payWayList = res.object;
        for (let key in payWayList) {
          if (key == 0) {
            payWayList[key]['isChecked'] = true;
            this.paywayId = payWayList[key].paywayId;
          } else {
            payWayList[key]['isChecked'] = false;
          }
        }
        console.log(payWayList);
        this.radios = payWayList;
      })

    },
    components: {}
  }
</script>
<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped lang="less" rel="stylesheet/less">
  .bg {
    background-color: rgba(0, 0, 0, 0.3);
    width: 100%;
    height: 100%;
    position: fixed;
    top: 0;
    left: 0;
    bottom: 50px;
  }

  .model .modelContent {
    background-color: #fff;
    border-radius: 8px;
    position: fixed;
    left: 50%;
    top: 50%;
    margin-left: -43%;
    margin-top: -111px;
    z-index: 2;
    padding: 40px 10px 20px;
    width: 80%;
    text-align: left;

    img {
      position: absolute;
      right: 10px;
      top: 10px
    }

    .btn {
      button {
        height: 42px;
        line-height: 42px;
        color: #fff;
        outline: none;
        border: none;
        width: calc(50% - 20px);
        border-radius: 8px;
        margin-top: 25px;
      }

      :last-child {
        background-color: #aaa;

      }

      :first-child {
        background-color: #f98e3c;
        margin-right: 20px;

      }
    }

  }

  .offer {
    position: fixed;
    bottom: 0;
    width: 100%;
    background-color: #f98e3c;
    height: 50px;
    line-height: 50px;
    color: #fff;
    z-index: 2;
  }

  .otherOffer {
    position: fixed;
    bottom: 0;
    width: 100%;
    background-color: #ccc;
    height: 50px;
    line-height: 50px;
    color: #fff;
    z-index: 2;
  }

  .uploadtitle {
    font-size: 13px;
    color: #f98e3c;
    margin: 10px 10px 0;
    text-align: left;
  }

  .upload {
    border: 2px dashed #f98e3c;
    text-align: center;
    color: #f98e3c;
    font-size: 13px;
    padding: 30px 10px 70px;
    margin: 15px 10px 70px;

    p {
      margin-bottom: 10px;
    }
  }

  .choose {
    color: #999;
    font-size: 15px;
    text-align: left;
    padding: 10px 10px 0;
  }

  .chooseway {
    li {
      border-bottom: 1px solid #eee;
      padding: 10px 0;
      margin: 10px;
    }

    :last-child {
      border-bottom: none;
    }
  }

  .radio-box {
    position: relative;
    height: 25px;
    line-height: 25px;
    font-size: 15px;
    color: #111;
    text-align: left;
    display: flex;

    label {
      flex: 1;
    }

    img {
      vertical-align: middle;
      margin-right: 10px;
      width: 20px;
    }

    .input-radio {
      display: inline-block;
      position: absolute;
      opacity: 0;
      width: 25px;
      height: 25px;
      cursor: pointer;
      right: 0;
      top: 0;
      outline: none;
      -webkit-appearance: none;
    }
  }

  .radio {
    display: inline-block;
    width: 25px;
    height: 25px;
    vertical-align: middle;
    cursor: pointer;
    background: url(../../../assets/radio.png) no-repeat;
    background-size: 100% 100%;

  }

  .on {
    background-image: url(../../../assets/cheaked.png);
    background-size: 100% 100%;
  }

  .tip {
    background-color: #f84743;
    color: #fff;
    text-align: left;
    padding: 10px;

    p:first-child {
      font-size: 15px;
      margin-bottom: 5px;
    }

    p:last-child {
      font-size: 17px;
      font-weight: 700;
    }
  }

  .total {
    font-size: 15px;
    color: #111;
    padding: 10px;
    text-align: left;

    span {
      float: right;
      color: #f98e3c;
    }
  }

  .divider {
    height: 10px;
    background-color: #eee;
  }

  .msg {
    position: relative;

    .num {
      position: absolute;
      right: 10px;
      bottom: 15px;
      font-size: 15px;
      color: #666;
    }
  }

  .weui-media-box_appmsg .weui-media-box__hd {
    width: 100px;
    height: auto;
  }

  .weui-media-box_appmsg .weui-media-box__bd {
    text-align: left;
  }

  .weui-media-box__title {
    font-size: 15px;
    color: #666;
    margin-bottom: 25px;
  }

  .weui-media-box__desc {
    font-size: 25px;
    color: #111;
  }
</style>
